package com.tour.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * @ClassName RouteController
 * @Author 张梦兴
 * @Date 2020/3/10 20:57
 * @describe
 */
@Controller
public class RouteController {

    /**
     * 到后台登录页面
     * @return
     */
    @RequestMapping("/manage")
    public String toLogin(){
        return "/admin/login";
    }

    /**
     * 到管理员后台页面
     * @return
     */
    @RequestMapping("/managePage")
    public String toManage(){
        return "admin/scenic_spot_manage";
    }

    /**
     * 后台页面退出，清除session
     * @param request
     * @return
     */
    @RequestMapping("/manage/logout")
    public String toLogout(HttpServletRequest request){
        request.getSession().removeAttribute("admin");
        return "/admin/login";
    }

    /**
     * 到景区管理页面
     * @return
     */
    @RequestMapping("admin/scenic_spot")
    public String toScenicSpotManage(){
        return "admin/scenic_spot_manage";
    }

    /**
     * 到添加景区页面
     * @return
     */
    @RequestMapping("admin/scenic_spot_add")
    public String toAddScenicSpot(){
        return "admin/scenic_spot_add";
    }

    /**
     * 到用户注册页面
     * @return
     */
    @RequestMapping("register")
    public String toRegister(){
        return "user/register";
    }

    /**
     * 到用户登录页面
     * @return
     */
    @RequestMapping("userLogin")
    public String toUserLogin(){
        return "user/login";
    }

    /**
     * 到景区详细列表
     * @return
     */
    @RequestMapping("scenic_spot/list")
    public ModelAndView toScenicSpotList(@RequestParam(value = "scenicTitle" ,required = false) String title,
                                         @RequestParam(value = "scenicStar" ,required = false)String star){
        ModelAndView mv=new ModelAndView("scenic_spot/list");
            mv.addObject("title", title);
            mv.addObject("star",star);
        return mv;
    }

    /**
     * 到个人中心
     * @return
     */
    @RequestMapping("user/center")
    public String toPersonCenter(){
        return "user/person_center";
    }

    /**
     * 到酒店详细列表
     * @return
     */
    @RequestMapping("hotel/list")
    public ModelAndView toHotelList(@RequestParam(value = "hotelTitle" ,required = false) String hotelTitle,
                              @RequestParam(value = "hotelAddress" ,required = false)String hotelAddress){
        ModelAndView mv=new ModelAndView("hotel/list");
        mv.addObject("title", hotelTitle);
        mv.addObject("address",hotelAddress);
        return mv;
    }

    /**
     * 到酒店管理页面
     * @return
     */
    @RequestMapping("admin/hotel")
    public String toHotelManage(){
        return "admin/hotel_manage";
    }

    /**
     * 到添加景区页面
     * @return
     */
    @RequestMapping("admin/hotel_add")
    public String toAddHotel(){
        return "admin/hotel_add";
    }

    /**
     * 到票务页面
     * @return
     */
    @RequestMapping("/ticket/list")
    public ModelAndView toTicketInfo(@RequestParam(value = "ticketStartStation" ,required = false) String ticketStartStation,
                               @RequestParam(value = "ticketLastStation" ,required = false)String ticketLastStation,
                               @RequestParam(value = "ticketStartDate" ,required = false)String ticketStartDate){
        ModelAndView mv=new ModelAndView("ticket/ticketInfo");
        mv.addObject("ticketStartStation", ticketStartStation);
        mv.addObject("ticketLastStation",ticketLastStation);
        mv.addObject("ticketStartDate",ticketStartDate);
        return mv;
    }

    /**
     * 到票务管理页面
     * @return
     */
    @RequestMapping("admin/ticket")
    public String toTicketManage(){
        return "admin/ticket_manage";
    }

    /**
     * 到留言管理页面
     * @return
     */
    @RequestMapping("admin/messageList/{modtype}/{modid}")
    public String toMessageList(@PathVariable("modtype") String modtype,@PathVariable("modid") int modid, Map<String,Object> map){
        map.put("modtype", modtype);
        map.put("modid",modid);
        return "admin/messageList";
    }

    /**
     * 到用户管理
     * @return
     */
    @RequestMapping("admin/user")
    public String toUserManage(){
        return "admin/user_manage";
    }

    /**
     * 到用户管理
     * @return
     */
    @RequestMapping("admin/index")
    public String toIndexManage(){
        return "admin/index_manage";
    }
}
